<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>


<script type="text/html" id="toolbarDemo">

    <button class="layui-btn layui-btn-sm" lay-event="insert" id="addUser"><i
            class="layui-icon">&#xe654;</i>新增
    </button>
    <button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>
    <div class="layui-inline" style="float:right;height:29px;" title="搜索" lay-event="search"><i
            class="layui-icon layui-icon-search"></i></div>
    <div class="layui-inline layui-show-xs-block">
        <label class="layui-form-label layui-bg-gray" style="left: 1150px; width: 110px;text-align: center">交易所名称</label>
        <div class="layui-inline layui-show-xs-block" style="left: 1150px">
            <select name="exchangeName" id="exchangeName">
                <option value="0">啥也没有</option>
                <option value="2">上交所</option>
                <option value="1">深交所</option>
            </select>
        </div>
    </div>



</script>
<script type="text/html" id="Broker">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="layui/layui.js"></script>


<script>
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：/docs/modules/table.html#totalRow
        table.render({
            height: 'full-55'
            , minLength: 80,
            elem: '#myTable'
            , id: 'tableId'
            , url: '/selectExchangeRateMap'
            , toolbar: '#toolbarDemo'
            , title: '交易品种费率'
            , cols: [[
                {type: 'checkbox', field: 'left'}
                , {
                    field: 'exchangeName', title: '交易所名称', templet: function (ExchangeRate) {
                        if (ExchangeRate.exchangeName == 1) {
                            return '深圳交易所';
                        } else if (ExchangeRate.exchangeName == 2) {
                            return '上海交易所';
                        }
                    }
                }
                , {field: 'exchangeType', title: '交易品种',templet: function (ExchangeRate) {
                        if (ExchangeRate.exchangeType == 1) {
                            return '股票';
                        } else if (ExchangeRate.exchangeType == 2) {
                            return '债券';
                        }
                    }
                }
                , {field: 'stampDuty', title: '印花税'}
                , {field: 'transferFee', title: '过户费'}
                , {field: 'collectionFee', title: '征管费'}
                , {field: 'handlingFee', title: '经手费'}
                , {fixed: 'right', title: '操作', toolbar: '#Broker'}
            ]]
            , page: true
        });

        //工具栏事件
        table.on('toolbar(myTable2)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                    break;
            }
            ;

            if (obj.event == 'insert') {
                //点击按钮的时候，弹出一个添加页面
                layer.open({
                    type: 2,
                    title: "添加券商",
                    content: "addExchangeRate",
                    area: ['650px', '470px'],
                    //层销毁后触发
                    end: function () {
                        //刷新页面
                        table.reload('tableId');
                    }
                })
            }else if(obj.event=='search'){
                //alert('根据条件查询')
                var exchangeName=$("#exchangeName").val();
                console.log(exchangeName)
                //表格的重新加载事件
                table.reload('tableId', {
                    method: 'post'
                    , where: {
                        'exchangeName': exchangeName,
                    }
                    , page: {
                        curr: 1
                    }
                });
            }
        });
        table.on('tool(myTable2)', function (obj) {
            switch (obj.event) {
                case "del":
                    layer.confirm('您确定要删除吗', function (index) {
                        $.getJSON("deleteExchangeRate"
                            , {exchangeName: obj.data.exchangeName}
                            , function (msg) {
                                if (msg == 1) {
                                    layer.close(index)
                                    table.reload('tableId');
                                }
                            })
                    })
                    break;
                case "edit":
                    layer.open({
                        type: 2,
                        title: "修改券商",
                        content: "updateExchangeRate",
                        area: ['650px', '470px'],
                        success:function (layero,index) {
                            var body = layer.getChildFrame('body',index);
                            console.log(obj.data.brokerId)
                            body.find("#exchangeName").val(obj.data.exchangeName);
                            if (body.find("#exchangeType").val(obj.data.exchangeType)==1){
                                body.find("#exchangeType").val= '深圳交易所';
                            } else if (body.find("#exchangeType").val(obj.data.exchangeType)==1) {
                                body.find("#exchangeType").val= '上海交易所';
                            };
                            body.find("#stampDuty").val(obj.data.stampDuty);
                            body.find("#transferFee").val(obj.data.transferFee);
                            body.find("#collectionFee").val(obj.data.collectionFee);
                            body.find("#handlingFee").val(obj.data.handlingFee);
                        },
                        //层销毁后触发
                        end: function () {
                            //刷新页面
                            table.reload('tableId');
                        }
                    })
                    break;
            }
        })
    });
</script>
<table class="layui-hide" id="myTable" lay-filter="myTable2" ></table>
</body>
</html>